Redis : Basic Usage#1
2016/09/06 |
This is the Basic Usage of Redis with "redis-cli" client program.
Following examples are basic one, you can see more commands on Official Site below.
⇒ http://redis.io/commands |
|
[1] | Connect to Redis Server like follows. |
# connect to local server # password is the one you set on redis.conf root@dlp:~# redis-cli -a password # exit from connection 127.0.0.1:6379> quit # possible to authenticate after connecting to Server root@dlp:~# redis-cli 127.0.0.1:6379> auth password OK # connect to a Database with specifying Database-ID explicitly # if Database-ID is not specified, connect to Database-ID "0" root@dlp:~# redis-cli -a password -n 1 127.0.0.1:6379[1]> # change to Database-ID "2" 127.0.0.1:6379[1]> select 2 OK 127.0.0.1:6379[2]> # for connecting to Redis on another Host, specify "-h [hostname]" root@dlp:~# redis-cli -h node01.srv.world -a password 10.0.0.51:6379> # possible to get results with non-interactively with redis-cli # for example, get Value of a Key root@dlp:~# redis-cli -a password get key01 "value02" |
[2] | This is the basic Usage of control Redis Server itself. |
root@dlp:~#
redis-cli -a password # refer to statics 127.0.0.1:6379> info # Server redis_version:3.0.6 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:687a2a319020fa42 redis_mode:standalone os:Linux 4.4.0-28-generic x86_64 arch_bits:64 ..... ..... # show connected clients 127.0.0.1:6379> client list id=3 addr=127.0.0.1:44474 fd=5 name= age=447 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client id=4 addr=10.0.0.31:43668 fd=6 name= age=10 idle=10 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=auth # kill connection of a client 127.0.0.1:6379> client kill 10.0.0.31:43668 OK # dump all requests after the command below 127.0.0.1:6379> monitor OK 1469078099.850114 [0 10.0.0.31:43666] "get" "key01" 1469078112.319154 [0 10.0.0.31:43666] "set" "key02" "value02" ..... ..... # save data on disk with foreground 127.0.0.1:6379> save OK # save data on disk with background 127.0.0.1:6379> bgsave Background saving started # get UNIX time stamp of the last save to disk 127.0.0.1:6379> lastsave (integer) 1469078407 # save data on disk and shutdown Redis 127.0.0.1:6379> shutdown not connected> quit root@dlp:~# ps aux | grep [r]edis |